<?php
require('../global.php');
?>
<!DOCTYPE html>
<html>
<head>
<?php require('admin/_head.php'); ?>
<title>登录 - <?php echo getconfig('title'); ?>管理后台</title>
<script>if(window.top !== window.self){window.top.location = window.location;}</script>
</head>

<body class="gray-bg">
	
    <div class="middle-box text-center loginscreen animated fadeInDown">
        <h1 class="logo-name" style="font-size:50px;"><?php echo getconfig('title'); ?></h1>
        <div class="form text-left">
            <form class="m-t" id="loginForm" action="login.ajax.php">
            	<input type="hidden" name="ac" value="login">
                <div class="form-group">
                    <input type="email" class="form-control" name="username" id="username" placeholder="用户名" datatype="*" nullmsg="请输入用户名！">
                    <span class="help-block m-b-none"></span>
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" name="password" id="password" placeholder="密码" datatype="*" nullmsg="请输入密码！">
                    <span class="help-block m-b-none"></span>
                </div>
                <button type="submit" class="btn btn-primary block full-width m-b" id="btn-submit">登 录</button>
            </form>
        </div>
    </div>
    <?php require('admin/_js.php'); ?>
    <script src="js/plugins/validform/Validform_min.js"></script>
    <script src="js/plugins/validform/Validform_Datatype.js"></script>
    <script>
    $(function(){
        var form = $('#loginForm').Validform({
    		btnSubmit: '#btn-submit',
    		postonce: false,
    		showAllError: true,
    		//msg：提示信息;
    		//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
    		//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
    		tiptype: function(msg, o){
    			if(!o.obj.is('form')){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
    				var B = o.obj.parents('.form-group');
    				var T = B.find('.help-block');
    				if(o.type == 2){
    					B.removeClass('has-error').addClass('has-success');
    					T.html('');
    				}else{
    					B.removeClass('has-success').addClass('has-error');
    					T.html("<i class='fa fa-times-circle'></i> " + msg);
    				}
    			}
    		},
    		ajaxPost: true,
    		callback: function(data){
				if(data.status == 'y'){
                    location.href = 'index.php';
				}else{
                    swal({
                        title: "登录失败",
                        text: "提示信息：" + data.info,
                        type: "error"
                    }, function(){
                        $('#password').val('');
                    });
				}
    		}
    	});
    });
    </script>
</body>
</html>
